/**
 * BehaviorDecorator class definition
 * Base class for the specific decorators.
 * Decorates all the task methods except for Execute, for commodity. 
 * (Though any method can be decorated in the base classes with no problem, 
 * they are decorated by default so the programmer does not forget)
 * 
 * Original credit for a java implementation to: http://magicscrollsofcode.blogspot.com/2010/12/behavior-trees-by-example-ai-in-android.html
 */

#ifndef BEHAVIORDECORATOR_H_
#define BEHAVIORDECORATOR_H_

#include "BaseBehavior.h"

class BehaviorDecorator : public BaseBehavior 
{
public:
	/**
	 * Creates a new instance of the Decorator class
	 * @param incBehavior BaseBehavior to decorate
	 */
	BehaviorDecorator(BaseBehavior* incBehavior) : behavior(incBehavior) 
	{
		DEBUG_PRINT("Created behavior decorator\n");
		InitBehavior(incBehavior);
	}

	/**
	 * Decorate the CheckConditions
	 */
	virtual bool CheckConditions() {	return behavior->CheckConditions();	}

	/**
	 * Decorate the end
	 */
	virtual void Exit() {	behavior->Exit();	}

	virtual void Execute()	{	behavior->Execute();	}

	/**
	 * Decorate the request for the Control reference
	 */
	BehaviorController* GetControl() {	return behavior->GetControl();	}

	virtual void Enter() {	behavior->Enter();	}

protected:
	/**
	 * Reference to the behavior to decorate
	 */
	BaseBehavior* behavior;

private:
	/**
	 * Initializes the task reference
	 * @param task Task to decorate
	 */
	void InitBehavior(BaseBehavior* incBehavior)
	{
		behavior = incBehavior;
		behavior->GetControl()->SetBehavior(this);
	}

};

#endif
